/*******************************************************************************
 * Copyright (c) 2011 squid.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     squid - initial API and implementation
 ******************************************************************************/
package com.google.code.cubeirc.base;

import lombok.Getter;
import lombok.Setter;

import org.apache.log4j.Level;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.widgets.Composite;

import com.google.code.cubeirc.common.Utils;
import com.google.code.cubeirc.debug.DebuggerQueue;
import com.google.code.cubeirc.queue.MessageQueue;
import com.google.code.cubeirc.queue.MessageQueueEvent;
import com.google.code.cubeirc.queue.MessageQueueListener;

public class BaseTab extends Composite  implements IBase, MessageQueueListener  {

	@Getter @Setter
	private String tabName;
	
	public BaseTab(Composite composite, int style, String name) {
		super(composite, style);
		setTabName(name);
		MessageQueue.addListener(this);
		
	}

	@Setter @Getter
	private CTabItem tabitem;
	
	@Override
	public boolean Close() {
		addDebug(Level.DEBUG, "%s: Executing Close() function",getTabName());
		MessageQueue.removeListener(this);
		this.dispose();
		getTabitem().dispose();
		return true;
	}

	@Override
	public void Init() {
		
	}
	
	@Override
	public void actionPerformed(MessageQueueEvent e) {
		
		
	}
	
	
	protected void addDebug(Level level, String text, Object ... args)
	{
		DebuggerQueue.addDebug(getTabName(), level, text, args);
	}
	
	
	protected void asyncExec(Runnable runnable) {
		Utils.asyncExec(getDisplay(), runnable);		
	}
	

}
